﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using SD.Database.Classes;
using DBAccess;

namespace SD.Database
{
    public partial class StoredProcedures
    {
        public static void RestartGame()
        {
            DAL dal = DAL.GetInstance();
            dal.DeleteData("Delete from News");
            dal.DeleteData("Delete from fleets");
            dal.DeleteData("Delete from Battles");
            dal.DeleteData("Delete from Planets");
            dal.DeleteData("Delete  from AllianceMembers");
            dal.DeleteData("Delete  from Alliances");
            dal.DeleteData("Delete  from Artifacts");
            dal.DeleteData("Delete  from Players Where PlayerId > 1");
            dal.DeleteData("Delete  from Intel");
            dal.DeleteData("Delete  from Systems");

            dal.UpdateData("Update Configuration set PlayersInLastSystem = 0, LastOrginID = 1, SupplyUnitsPrice= 1500");
            using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(@"Delete from News", conn))
                {
                    cmd.CommandText = "Drop TABLE Systems";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = @"CREATE TABLE [dbo].[Systems](
	                [SystemID] [int] IDENTITY(1,1) NOT NULL,
	                [SystemName] [nvarchar](50) COLLATE Polish_CI_AS NOT NULL,
	                [X] [int] NOT NULL,
	                [Y] [int] NOT NULL)";
                    cmd.ExecuteNonQuery();
                }
            }
            CreateGame();
        }
    };
}